package com.syni.mdd.sjb.common.datatreaure.service.impl.databank.saasminapp;

import com.alibaba.fastjson.JSON;
import com.syni.mdd.sjb.common.component.utils.common.utils.*;
import com.syni.mdd.sjb.common.component.utils.feign.service.mdd.commonuser.UserRestService;
import com.syni.mdd.sjb.common.datatreaure.constants.ResultMsg;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rq.databank.MemberRqVo;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rq.saasminapp.config.StoreIdVo;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rq.saasminapp.order.*;
import com.syni.mdd.sjb.common.datatreaure.service.databank.saasminapp.MinOrderService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
@Log4j2
public class MinOrderServiceImpl implements MinOrderService {
    @Autowired
    private UserRestService userRestService;

    @Override
    public Map<String, Object> getDelivery(MemberRqVo memberRqVo) {
        try{
            String postUrl = AppConfig.getProperty("saas.dxshapp.store.center.service") + "/sys/store/delivery/config/get";
            Map<String,Object> params = new HashMap<>();
            params.put("storeId", memberRqVo.getStoreId());
            Map<String, Object> resultMap = getReqWithHead(postUrl, memberRqVo.getToken(), memberRqVo.getUserId(),true,params, params);
            if(resultMap != null && StringUtils.equals(resultMap.get("code").toString(),"200")){
                return ResultMapHelper.success(resultMap.get("data"), ResultMsg.HAND_SUCCESS);
            }
        }catch (Exception e){
            log.info(e.getMessage(),e);
        }
        return ResultMapHelper.failure(ResultMsg.HAND_FAIL);
    }

    @Override
    public Map<String, Object> getOrderByPage(GetOrderListVo getOrderListVo) {
        try{
            Map<String,Object> headMap = new HashMap<>();
            headMap.put("storeId",getOrderListVo.getStoreId());
            String postUrl = AppConfig.getProperty("saas.dxshapp.order.center.service") + "/oms/OmsOrder/getOrderByPage";
            Map<String, Object> params = BeanUtils.objectToMap(getOrderListVo);
            params.put("pageNo",getOrderListVo.getPageNum());
            Map<String, Object> resultMap = getReqWithHead(postUrl, getOrderListVo.getToken(), getOrderListVo.getUserId(),true,headMap, params);
            if(ResultMapHelper.isSuccess(resultMap)){
                return ResultMapHelper.success(resultMap.get("data"),ResultMsg.HAND_SUCCESS);
            }else{
                return ResultMapHelper.failure(resultMap.get("msg").toString());
            }
        }catch (Exception e){
            log.info(e.getMessage(),e);
        }
        return ResultMapHelper.failure(ResultMsg.HAND_FAIL);
    }

    @Override
    public Map<String, Object> getOrderDetail(GetOrderDetailVo getOrderDetailVo) {
        try{
            Map<String,Object> headMap = new HashMap<>();
            headMap.put("storeId",getOrderDetailVo.getStoreId());
            String postUrl = AppConfig.getProperty("saas.dxshapp.order.service") + "oms/OmsOrder/" + getOrderDetailVo.getId();
            Map<String, Object> resultMap = getReqWithHead(postUrl, getOrderDetailVo.getToken(), getOrderDetailVo.getUserId(),true,headMap, new HashMap<>());
            if(ResultMapHelper.isSuccess(resultMap)){
                return ResultMapHelper.success(resultMap.get("data"),ResultMsg.HAND_SUCCESS);
            }else{
                return ResultMapHelper.failure(resultMap.get("msg").toString());
            }
        }catch (Exception e){
            log.info(e.getMessage(),e);
        }
        return ResultMapHelper.failure(ResultMsg.HAND_FAIL);
    }

    @Override
    public Map<String, Object> cancelOrder(GetOrderDetailVo getOrderDetailVo) {
        try{
            Map<String,Object> headMap = new HashMap<>();
            headMap.put("storeId",getOrderDetailVo.getStoreId());
            String postUrl = AppConfig.getProperty("saas.dxshapp.order.service") + "oms/OmsOrder/cancelOrder/" + getOrderDetailVo.getId();
            Map<String, Object> resultMap = postReqMember(postUrl, getOrderDetailVo.getToken(), getOrderDetailVo.getUserId(),true, headMap,new HashMap<>());
            if(ResultMapHelper.isSuccess(resultMap)){
                return ResultMapHelper.success(resultMap.get("data"),ResultMsg.HAND_SUCCESS);
            }else{
                return ResultMapHelper.failure(resultMap.get("msg").toString());
            }
        }catch (Exception e){
            log.info(e.getMessage(),e);
        }
        return ResultMapHelper.failure(ResultMsg.HAND_FAIL);
    }

    @Override
    public Map<String, Object> deleteOrder(GetOrderDetailVo getOrderDetailVo) {
        try{
            Map<String,Object> headMap = new HashMap<>();
            headMap.put("storeId",getOrderDetailVo.getStoreId());
            String postUrl = AppConfig.getProperty("saas.dxshapp.order.service") + "oms/OmsOrder/deleteOrder/" + getOrderDetailVo.getId();
            Map<String, Object> resultMap = postReqMember(postUrl, getOrderDetailVo.getToken(), getOrderDetailVo.getUserId(),true, headMap,new HashMap<>());
            if(ResultMapHelper.isSuccess(resultMap)){
                return ResultMapHelper.success(resultMap.get("data"),ResultMsg.HAND_SUCCESS);
            }else{
                return ResultMapHelper.failure(resultMap.get("msg").toString());
            }
        }catch (Exception e){
            log.info(e.getMessage(),e);
        }
        return ResultMapHelper.failure(ResultMsg.HAND_FAIL);
    }

    @Override
    public Map<String, Object> completeOrder(GetOrderDetailVo getOrderDetailVo) {
        try{
            Map<String,Object> headMap = new HashMap<>();
            headMap.put("storeId",getOrderDetailVo.getStoreId());
            String postUrl = AppConfig.getProperty("saas.dxshapp.order.service") + "oms/OmsOrder/completeOrder/" + getOrderDetailVo.getId();
            Map<String, Object> resultMap = postReqMember(postUrl, getOrderDetailVo.getToken(), getOrderDetailVo.getUserId(),true, headMap,new HashMap<>());
            if(ResultMapHelper.isSuccess(resultMap)){
                return ResultMapHelper.success(resultMap.get("data"),ResultMsg.HAND_SUCCESS);
            }else{
                return ResultMapHelper.failure(resultMap.get("msg").toString());
            }
        }catch (Exception e){
            log.info(e.getMessage(),e);
        }
        return ResultMapHelper.failure(ResultMsg.HAND_FAIL);
    }

    @Override
    public Map<String, Object> userHasPaid(GetOrderDetailVo getOrderDetailVo) {
        try{
            Map<String,Object> headMap = new HashMap<>();
            headMap.put("storeId",getOrderDetailVo.getStoreId());
            String postUrl = AppConfig.getProperty("saas.dxshapp.order.service") + "oms/OmsOrder/userHasPaid";
            Map<String,Object> params = new HashMap<>();
            params.put("id",getOrderDetailVo.getId());
            Map<String, Object> resultMap = postFormReqMember(postUrl, getOrderDetailVo.getToken(), getOrderDetailVo.getUserId(),true, headMap,params);
            if(ResultMapHelper.isSuccess(resultMap)){
                return ResultMapHelper.success(resultMap.get("data"),ResultMsg.HAND_SUCCESS);
            }else{
                return ResultMapHelper.failure(resultMap.get("msg").toString());
            }
        }catch (Exception e){
            log.info(e.getMessage(),e);
        }
        return ResultMapHelper.failure(ResultMsg.HAND_FAIL);
    }

    @Override
    public Map<String, Object> modifyPrice(ModifyPriceVo modifyPriceVo) {
        try{
            Map<String,Object> headMap = new HashMap<>();
            headMap.put("storeId",modifyPriceVo.getStoreId());
            String postUrl = AppConfig.getProperty("saas.dxshapp.order.service") + "oms/OmsOrder/modifyPrice";
            Map<String,Object> params = new HashMap<>();
            params.put("id",modifyPriceVo.getId());
            params.put("targetPrice",modifyPriceVo.getTargetPrice());
            Map<String, Object> resultMap = postFormReqMember(postUrl, modifyPriceVo.getToken(), modifyPriceVo.getUserId(),true, headMap,params);
            if(ResultMapHelper.isSuccess(resultMap)){
                return ResultMapHelper.success(resultMap.get("data"),ResultMsg.HAND_SUCCESS);
            }else{
                return ResultMapHelper.failure(resultMap.get("msg").toString());
            }
        }catch (Exception e){
            log.info(e.getMessage(),e);
        }
        return ResultMapHelper.failure(ResultMsg.HAND_FAIL);
    }

    @Override
    public Map<String, Object> printTicket(PrintTicketVo printTicketVo) {
        try{
            Map<String,Object> headMap = new HashMap<>();
            headMap.put("storeId",printTicketVo.getStoreId());
            String postUrl = AppConfig.getProperty("saas.dxshapp.order.service") + "oms/OmsOrder/printTicket";
            Map<String,Object> params = new HashMap<>();
            params.put("id",printTicketVo.getId());
            params.put("printType",printTicketVo.getPrintType());
            Map<String, Object> resultMap = postFormReqMember(postUrl, printTicketVo.getToken(), printTicketVo.getUserId(),true, headMap,params);
            if(ResultMapHelper.isSuccess(resultMap)){
                return ResultMapHelper.success(resultMap.get("data"),ResultMsg.HAND_SUCCESS);
            }else{
                return ResultMapHelper.failure(resultMap.get("msg").toString());
            }
        }catch (Exception e){
            log.info(e.getMessage(),e);
        }
        return ResultMapHelper.failure(ResultMsg.HAND_FAIL);
    }

    @Override
    public Map<String, Object> removeOrderItem(GetOrderDetailVo getOrderDetailVo){
        try{
            Map<String,Object> headMap = new HashMap<>();
            headMap.put("storeId",getOrderDetailVo.getStoreId());
            String postUrl = AppConfig.getProperty("saas.dxshapp.order.service") + "oms/OmsOrder/removeOrderItem";
            Map<String,Object> params = new HashMap<>();
            params.put("id",getOrderDetailVo.getId());
            Map<String, Object> resultMap = postFormReqMember(postUrl, getOrderDetailVo.getToken(), getOrderDetailVo.getUserId(),true, headMap,params);
            if(ResultMapHelper.isSuccess(resultMap)){
                return ResultMapHelper.success(resultMap.get("data"),ResultMsg.HAND_SUCCESS);
            }else{
                return ResultMapHelper.failure(resultMap.get("msg").toString());
            }
        }catch (Exception e){
            log.info(e.getMessage(),e);
        }
        return ResultMapHelper.failure(ResultMsg.HAND_FAIL);
    }

    @Override
    public Map<String, Object> netShop(NetShopVo netShopVo){
        try{
            Map<String,Object> headMap = new HashMap<>();
            headMap.put("storeId",netShopVo.getStoreId());
            String postUrl = AppConfig.getProperty("saas.dxshapp.order.service") + "oms/OmsOrder/netShop/ship";
            Map<String,Object> params = new HashMap<>();
            params.put("oid",netShopVo.getOid());
            params.put("deliveryType",netShopVo.getDeliveryType());
            params.put("insured",netShopVo.getInsured());
            params.put("delayTime",netShopVo.getDelayTime());
            Map<String, Object> resultMap = postFormReqMember(postUrl, netShopVo.getToken(), netShopVo.getUserId(),true, headMap,params);
            if(ResultMapHelper.isSuccess(resultMap)){
                return ResultMapHelper.success(resultMap.get("data"),ResultMsg.HAND_SUCCESS);
            }else{
                return ResultMapHelper.failure(resultMap.get("msg").toString());
            }
        }catch (Exception e){
            log.info(e.getMessage(),e);
        }
        return ResultMapHelper.failure(ResultMsg.HAND_FAIL);
    }

    @Override
    public Map<String, Object> getDadaComplaintReasons(StoreIdVo storeIdVo){
        try{
            Map<String,Object> headMap = new HashMap<>();
            headMap.put("storeId",storeIdVo.getStoreId());
            String postUrl = AppConfig.getProperty("saas.dxshapp.order.service") + "oms/OmsOrder/netShop/getDadaComplaintReasons";
            Map<String,Object> params = new HashMap<>();
            Map<String, Object> resultMap = postFormReqMember(postUrl, storeIdVo.getToken(), storeIdVo.getUserId(),true, headMap,params);
            if(ResultMapHelper.isSuccess(resultMap)){
                return ResultMapHelper.success(resultMap.get("data"),ResultMsg.HAND_SUCCESS);
            }else{
                return ResultMapHelper.failure(resultMap.get("msg").toString());
            }
        }catch (Exception e){
            log.info(e.getMessage(),e);
        }
        return ResultMapHelper.failure(ResultMsg.HAND_FAIL);
    }

    @Override
    public Map<String, Object> complaintDada(ComplainDadaVo complainDadaVo){
        try{
            Map<String,Object> headMap = new HashMap<>();
            headMap.put("storeId",complainDadaVo.getStoreId());
            String postUrl = AppConfig.getProperty("saas.dxshapp.order.service") + "oms/OmsOrder/netShop/complaintDada";
            Map<String,Object> params = new HashMap<>();
            params.put("oid",complainDadaVo.getOid());
            params.put("reasonId",complainDadaVo.getReasonId());
            Map<String, Object> resultMap = postFormReqMember(postUrl, complainDadaVo.getToken(), complainDadaVo.getUserId(),true, headMap,params);
            if(ResultMapHelper.isSuccess(resultMap)){
                return ResultMapHelper.success(resultMap.get("data"),ResultMsg.HAND_SUCCESS);
            }else{
                return ResultMapHelper.failure(resultMap.get("msg").toString());
            }
        }catch (Exception e){
            log.info(e.getMessage(),e);
        }
        return ResultMapHelper.failure(ResultMsg.HAND_FAIL);
    }

    @Override
    public Map<String, Object> dadaCancelReasons(StoreIdVo storeIdVo){
        try{
            Map<String,Object> headMap = new HashMap<>();
            headMap.put("storeId",storeIdVo.getStoreId());
            String postUrl = AppConfig.getProperty("saas.dxshapp.order.service") + "oms/OmsOrder/netShop/dadaCancelReasons";
            Map<String,Object> params = new HashMap<>();
            Map<String, Object> resultMap = postFormReqMember(postUrl, storeIdVo.getToken(), storeIdVo.getUserId(),true, headMap,params);
            if(ResultMapHelper.isSuccess(resultMap)){
                return ResultMapHelper.success(resultMap.get("data"),ResultMsg.HAND_SUCCESS);
            }else{
                return ResultMapHelper.failure(resultMap.get("msg").toString());
            }
        }catch (Exception e){
            log.info(e.getMessage(),e);
        }
        return ResultMapHelper.failure(ResultMsg.HAND_FAIL);
    }

    @Override
    public Map<String, Object> cancelDadaDelivery(CancelDeleveryVo cancelDeleveryVo){
        try{
            Map<String,Object> headMap = new HashMap<>();
            headMap.put("storeId",cancelDeleveryVo.getStoreId());
            String postUrl = AppConfig.getProperty("saas.dxshapp.order.service") + "oms/OmsOrder/netShop/cancelDadaDelivery";
            Map<String,Object> params = new HashMap<>();
            params.put("oid",cancelDeleveryVo.getOid());
            params.put("reasonId",cancelDeleveryVo.getReasonId());
            params.put("reasonStr",cancelDeleveryVo.getReasonStr());
            Map<String, Object> resultMap = postFormReqMember(postUrl, cancelDeleveryVo.getToken(), cancelDeleveryVo.getUserId(),true, headMap,params);
            if(ResultMapHelper.isSuccess(resultMap)){
                return ResultMapHelper.success(resultMap.get("data"),ResultMsg.HAND_SUCCESS);
            }else{
                return ResultMapHelper.failure(resultMap.get("msg").toString());
            }
        }catch (Exception e){
            log.info(e.getMessage(),e);
        }
        return ResultMapHelper.failure(ResultMsg.HAND_FAIL);
    }

    @Override
    public Map<String, Object> confirmGoods(CancelDeleveryVo cancelDeleveryVo){
        try{
            Map<String,Object> headMap = new HashMap<>();
            headMap.put("storeId",cancelDeleveryVo.getStoreId());
            String postUrl = AppConfig.getProperty("saas.dxshapp.order.service") + "oms/OmsOrder/netShop/confirmGoods";
            Map<String,Object> params = new HashMap<>();
            params.put("oid",cancelDeleveryVo.getOid());
            Map<String, Object> resultMap = postFormReqMember(postUrl, cancelDeleveryVo.getToken(), cancelDeleveryVo.getUserId(),true, headMap,params);
            if(ResultMapHelper.isSuccess(resultMap)){
                return ResultMapHelper.success(resultMap.get("data"),ResultMsg.HAND_SUCCESS);
            }else{
                return ResultMapHelper.failure(resultMap.get("msg").toString());
            }
        }catch (Exception e){
            log.info(e.getMessage(),e);
        }
        return ResultMapHelper.failure(ResultMsg.HAND_FAIL);
    }

    @Override
    public Map<String, Object> messageConfirm(MessageConfirmVo messageConfirmVo){
        try{
            Map<String,Object> headMap = new HashMap<>();
            headMap.put("storeId",messageConfirmVo.getStoreId());
            String postUrl = AppConfig.getProperty("saas.dxshapp.order.service") + "oms/OmsOrder/netShop/messageConfirm";
            Map<String,Object> params = new HashMap<>();
            params.put("oid",messageConfirmVo.getOid());
            params.put("isConfirm",messageConfirmVo.getIsConfirm());
            Map<String, Object> resultMap = postFormReqMember(postUrl, messageConfirmVo.getToken(), messageConfirmVo.getUserId(),true, headMap,params);
            if(ResultMapHelper.isSuccess(resultMap)){
                return ResultMapHelper.success(resultMap.get("data"),ResultMsg.HAND_SUCCESS);
            }else{
                return ResultMapHelper.failure(resultMap.get("msg").toString());
            }
        }catch (Exception e){
            log.info(e.getMessage(),e);
        }
        return ResultMapHelper.failure(ResultMsg.HAND_FAIL);
    }

    @Override
    public Map<String, Object> comfrimArrived(MessageConfirmCopyVo messageConfirmCopyVo){
        try{
            Map<String,Object> headMap = new HashMap<>();
            headMap.put("storeId",messageConfirmCopyVo.getStoreId());
            String postUrl = AppConfig.getProperty("saas.dxshapp.order.service") + "oms/OmsOrder/netShop/arrived";
            Map<String,Object> params = new HashMap<>();
            params.put("id",messageConfirmCopyVo.getId());
            Map<String, Object> resultMap = postFormReqMember(postUrl, messageConfirmCopyVo.getToken(), messageConfirmCopyVo.getUserId(),true, headMap,params);
            if(ResultMapHelper.isSuccess(resultMap)){
                return ResultMapHelper.success(resultMap.get("data"),ResultMsg.HAND_SUCCESS);
            }else{
                return ResultMapHelper.failure(resultMap.get("msg").toString());
            }
        }catch (Exception e){
            log.info(e.getMessage(),e);
        }
        return ResultMapHelper.failure(ResultMsg.HAND_FAIL);
    }

    @Override
    public Map<String, Object> pickedUp(MessageConfirmCopyVo messageConfirmCopyVo){
        try{
            Map<String,Object> headMap = new HashMap<>();
            headMap.put("storeId",messageConfirmCopyVo.getStoreId());
            String postUrl = AppConfig.getProperty("saas.dxshapp.order.service") + "oms/OmsOrder/netShop/pickedUp";
            Map<String,Object> params = new HashMap<>();
            params.put("id",messageConfirmCopyVo.getId());
            Map<String, Object> resultMap = postFormReqMember(postUrl, messageConfirmCopyVo.getToken(), messageConfirmCopyVo.getUserId(),true, headMap,params);
            if(ResultMapHelper.isSuccess(resultMap)){
                return ResultMapHelper.success(resultMap.get("data"),ResultMsg.HAND_SUCCESS);
            }else{
                return ResultMapHelper.failure(resultMap.get("msg").toString());
            }
        }catch (Exception e){
            log.info(e.getMessage(),e);
        }
        return ResultMapHelper.failure(ResultMsg.HAND_FAIL);
    }

    @Override
    public Map<String, Object> getTmplServiceList(StoreIdVo storeIdVo){
        try{
            String postUrl = AppConfig.getProperty("saas.dxshapp.store.center.service") + "/sys/store/service/getTmplServiceList";
            Map<String,Object> headMap = new HashMap<>();
            headMap.put("storeId",storeIdVo.getStoreId());
            Map<String, Object> resultMap = postReqMember(postUrl, storeIdVo.getToken(), storeIdVo.getUserId(),true, headMap ,new HashMap<>());
            if(ResultMapHelper.isSuccess(resultMap)){
                return ResultMapHelper.success(resultMap.get("data"),ResultMsg.HAND_SUCCESS);
            }else{
                return ResultMapHelper.failure(resultMap.get("msg").toString());
            }
        }catch (Exception e){
            log.info(e.getMessage(),e);
        }
        return ResultMapHelper.failure(ResultMsg.HAND_FAIL);
    }

    @Override
    public Map<String, Object> buyServicePrepay(BuyServicePrepayVo buyServicePrepayVo){
        try{
            String postUrl = AppConfig.getProperty("saas.dxshapp.store.center.service") + "/sys/store/service/buyServicePrepay";
            Map<String,Object> headMap = new HashMap<>();
            headMap.put("storeId",buyServicePrepayVo.getStoreId());
            Map<String,Object> params = BeanUtils.objectToMap(buyServicePrepayVo);
            Map<String, Object> resultMap = getReqWithHead(postUrl, buyServicePrepayVo.getToken(), buyServicePrepayVo.getUserId(),true, headMap ,params);
            if(ResultMapHelper.isSuccess(resultMap)){
                return ResultMapHelper.success(resultMap.get("data"),ResultMsg.HAND_SUCCESS);
            }else{
                return ResultMapHelper.failure(resultMap.get("msg").toString());
            }
        }catch (Exception e){
            log.info(e.getMessage(),e);
        }
        return ResultMapHelper.failure(ResultMsg.HAND_FAIL);
    }

    public Map<String,Object> getReqWithHead(String requestUrl,String token,Integer userId,Boolean isExtra,Map<String,Object> extraMap,Map<String,Object> params){
        Map<String,Object> resultMap = null;
        try {
            RpcResponseVo rpcResponseVo = userRestService.getMiniTokenByUserId_v2(userId,token);
            log.info("=====rpcResponseVo======" + rpcResponseVo);
            if(rpcResponseVo.isSuccess()){
                String minitoken = rpcResponseVo.getData().toString();
                Map<String, Object> saasHeader = RestTemplateUtils.getSassHeader(minitoken);
                if(isExtra){
                    saasHeader.putAll(extraMap);
                }
                String reponseBody = RestTemplateUtils.getForEntityWithHead(requestUrl,params,saasHeader);
                resultMap = JSON.parseObject(reponseBody,Map.class);
            }
        }catch (Exception e){
            log.error(e.getMessage(),e);
        }
        return resultMap;
    }

    public Map<String,Object> reqMember(String requestUrl,String token,Integer userId,Map<String,Object> params){
        Map<String,Object> resultMap = null;
        try {
            RpcResponseVo rpcResponseVo = userRestService.getMiniTokenByUserId_v2(userId,token);
            log.info("=====rpcResponseVo======" + rpcResponseVo);
            if(rpcResponseVo.isSuccess()){
                String minitoken = rpcResponseVo.getData().toString();
                String reponseBody = RestTemplateUtils.getForEntityWithHead(requestUrl,params,RestTemplateUtils.getSassHeader(minitoken));
                resultMap = JSON.parseObject(reponseBody,Map.class);
            }
        }catch (Exception e){
            log.error(e.getMessage(),e);
        }
        return resultMap;
    }

    public Map<String,Object> postReqMemberWithToken(String requestUrl,String minToken,Integer userId,
                                            Boolean isExtra,Map<String,Object> extraMap,Map<String,Object> params){
        Map<String,Object> resultMap = null;
        try {
            Map<String, Object> saasHeader = RestTemplateUtils.getSassHeader(minToken);
            if(isExtra){
                saasHeader.putAll(extraMap);
            }
            String reponseBody = RestTemplateUtils.postForEntityForJsonByLoadBalanced(requestUrl,params,saasHeader);
            resultMap = JSON.parseObject(reponseBody,Map.class);
        }catch (Exception e){
            log.error(e.getMessage(),e);
        }
        return resultMap;
    }

    public Map<String,Object> postReqMember(String requestUrl,String token,Integer userId,
                                Boolean isExtra,Map<String,Object> extraMap,Map<String,Object> params){
        Map<String,Object> resultMap = null;
        try {
            RpcResponseVo rpcResponseVo = userRestService.getMiniTokenByUserId_v2(userId,token);
            log.info("=====rpcResponseVo======" + rpcResponseVo);
            if(rpcResponseVo.isSuccess()){
                String minitoken = rpcResponseVo.getData().toString();
                Map<String, Object> saasHeader = RestTemplateUtils.getSassHeader(minitoken);
                if(isExtra){
                    saasHeader.putAll(extraMap);
                }
                String reponseBody = RestTemplateUtils.postForEntityForJsonByLoadBalanced(requestUrl,params,saasHeader);
                resultMap = JSON.parseObject(reponseBody,Map.class);
            }
        }catch (Exception e){
            log.error(e.getMessage(),e);
        }
        return resultMap;
    }

    public Map<String,Object> postFormReqMember(String requestUrl,String token,Integer userId,
                                Boolean isExtra,Map<String,Object> extraMap,Map<String,Object> params){
        Map<String,Object> resultMap = null;
        try {
            RpcResponseVo rpcResponseVo = userRestService.getMiniTokenByUserId_v2(userId,token);
            log.info("=====rpcResponseVo======" + rpcResponseVo);
            if(rpcResponseVo.isSuccess()){
                String minitoken = rpcResponseVo.getData().toString();
                Map<String, Object> saasHeader = RestTemplateUtils.getSassHeader(minitoken);
                if(isExtra){
                    saasHeader.putAll(extraMap);
                }
                String reponseBody = RestTemplateUtils.postForEntity(RestTemplateUtils.getLoadRestTemplate(),requestUrl,params,saasHeader);
                resultMap = JSON.parseObject(reponseBody,Map.class);
            }
        }catch (Exception e){
            log.error(e.getMessage(),e);
        }
        return resultMap;
    }


}
